package Demo3;

import java.sql.Time;
import java.util.Random;

public class Main15 {
    static int[]array=new int[10000000];
    static  int sum1=0;
    static int sum2=0;
    public static void main(String[] args) throws InterruptedException {
        Random r=new Random();
        for (int i = 0; i <10000000 ; i++) {
            array[i]=r.nextInt(100)+1;
        }

        long start=System.currentTimeMillis();
        Thread t1=new Thread(()->{

            for (int i = 0; i <10000000 ; i+=2) {
                //sum1+=array[i];
                sum1++;
            }
        });
        Thread t2=new Thread(()->{
            for (int i = 1; i <10000000 ; i++) {
               // sum2+=array[i];
                sum2++;
            }
        });
t1.start();
t2.start();
t1.join();
t2.join();
        System.out.println("和为："+sum1+sum2);
long end=System.currentTimeMillis();
        System.out.println("程序执行时间"+(end-start));
    }
}
